<template>
  <div class="home">
    <div class="home-nav">
      <a-row :gutter="12">
        <a-col :span="304" v-for="(item, i) in nav" :key="i" :class="[item.disabled ? 'disabled' : 'pos']">
          <a-dropdown :trigger="['click']">
            <h-card
              size="large"
              :content="item.content"
              :url="item.url"
              :imgW="item.w"
              @click.native="toPath(item)"
              :disable="item.disabled"
              :disabledMsg="item.disabledMsg">
              <h-tooltip v-if="item.que" :title="item.que" />
            </h-card>
            <a-menu slot="overlay" v-if="item.children">
              <a-menu-item v-for="el in item.children" :key="el.path">
                <a href="javascript:;" @click="toPath(el)">{{ el.title }}</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          <div class="filter" v-if="item.disabled"></div>
        </a-col>
      </a-row>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
import { constantRouterMap } from '@/config/router.config';
import { getWebLinksLists } from '@/api/serve';

const emergency = constantRouterMap.find(e => e.path == '/emergency').children.map(e => {
  return {
    title: e.meta.title,
    path: e.path
  };
});

// 2 专网 1互联网
const isZw = process.env.VUE_APP_TYPE == 2;

export default {
  inject: ['refresh'],
  data() {
    return {
      source: 1,
      nav: [
        {
          content: '中央网信办<br>业务系统专区',
          url: require('@/assets/Image/icon/icon1.png'),
          w: 60,
          disabled: !isZw,
          disabledMsg: '',
          children: []
          // que: '这个跳哪里？'
        },
        {
          content: '浙江省网信办<br>业务系统专区',
          url: require('@/assets/Image/icon/icon1.png'),
          w: 60,
          disabled: !isZw,
          disabledMsg: '',
          children: []
          // que: '这个跳哪里？'
        },
        {
          content: '宁波市网信办<br>业务系统专区',
          url: require('@/assets/Image/icon/icon1.png'),
          w: 60,
          disabled: !isZw,
          disabledMsg: '',
          children: []
          // que: '这个跳哪里？'
        },
        {
          content: '平台专区',
          url: require('@/assets/Image/icon/icon2.png'),
          w: 73,
          children: []
          // path: '/safeInter'
        },
        {
          content: '属地数据',
          url: require('@/assets/Image/icon/icon3.png'),
          w: 78,
          children: [
            {
              title: '网络账号数据库',
              path: '/db/account'
            },
            {
              title: '网信专项整治数据库',
              path: '/db/SpecialRectificatio'
            },
            {
              title: '网信执法案例数据库',
              path: '/db/EnforcementCases'
            },
            {
              title: '网信普法基地数据库',
              path: '/db/Popularizing'
            },
            {
              title: '网络安全专家库',
              path: '/db/Enforcement'
            },
            {
              title: '重点网信企业数据库',
              path: '/db/StressEnterprises'
            },
            {
              title: '网信党建数据库',
              path: '/db/dangindex'
            }
          ]
        },
        {
          content: '处置协作',
          url: require('@/assets/Image/icon/icon4.png'),
          w: 70,
          children: [
            {
              title: '区县市网信办',
              path: '/cooperation/index?isOut=0'

            },
            {
              title: '市级部门',
              path: '/cooperation/indexOut?isOut=1'

            }
          ]
        },
        {
          content: '应急处置<br>工具专区',
          url: require('@/assets/Image/icon/icon5.png'),
          w: 61,
          children: emergency
        }
      ]
    };
  },
  created() {
    this.getWebLinksLists();
  },
  methods: {
    toPath({ path, reload, link }) {
      if (link) {
        window.open(link);
        return;
      }
      if (path) {
        this.$router.push({ path });
        if (reload) {
          this.refresh();
        }
      }
    },
    getWebLinksLists() {
      // 国
      getWebLinksLists({
        type: 0
      }).then(res => {
        this.nav[0].children = res.data;
      });
      // 省
      getWebLinksLists({
        type: 1
      }).then(res => {
        this.nav[1].children = res.data;
      });
      // 平台专区
      getWebLinksLists({
        type: 2
      }).then(res => {
        this.nav[3].children = res.data;
      });
      // 市
      getWebLinksLists({
        type: 3
      }).then(res => {
        this.nav[2].children = res.data;
      });
    }
  }
};
</script>
<style lang="less">
  .home-nav {
    margin-left: -10px;
    .pos {
      position: relative;
    }
    .disabled{
      // opacity: 0.7;
      .hcard {
        cursor: not-allowed !important;
      }
    }
  }

</style>
